<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录 - [[${configs.title}]]管理系统</title>
    <link rel="stylesheet" href="/statics/layui-v2.8.15/css/layui.css">
    <style type="text/css">

        #LAY-user-login, .layadmin-user-display-show {
            display: block !important
        }

        .layadmin-user-login {
            position: relative;
            left: 0;
            top: 0;
            padding: 110px 0;
            min-height: 100%;
            box-sizing: border-box
        }

        .layadmin-user-login-main {
            width: 520px;
            margin: 0 auto;
            box-sizing: border-box
        }

        .layadmin-user-login-box {
            padding: 20px
        }

        .layadmin-user-login-header {
            text-align: center
        }

        .layadmin-user-login-header h2 {
            margin-bottom: 10px;
            font-weight: 300;
            font-size: 22px;
            color: #000
        }

        .layadmin-user-login-header p {
            font-weight: 300;
            color: #999
        }

        .layadmin-user-login-body .layui-form-item {
            position: relative
        }

        .layadmin-user-login-icon {
            position: absolute;
            left: 1px;
            top: 1px;
            width: 38px;
            line-height: 36px;
            text-align: center;
            color: #d2d2d2
        }

        .layadmin-user-login-codeimg {
            max-height: 38px;
            width: 100%;
            cursor: pointer;
            box-sizing: border-box
        }

        .layadmin-user-login-other > * {
            display: inline-block;
            vertical-align: middle;
            margin-right: 10px;
            font-size: 14px
        }

        .layadmin-user-login-other .layui-icon {
            position: relative;
            top: 2px;
            font-size: 26px
        }

        .layadmin-user-login-other a:hover {
            opacity: .8
        }

        .layadmin-user-jump-change {
            float: right
        }

        .layadmin-user-login-footer {
            position: absolute;
            left: 0;
            bottom: 0;
            width: 100%;
            line-height: 30px;
            padding: 20px;
            text-align: center;
            box-sizing: border-box;
            color: rgba(0, 0, 0, .5)
        }

        .layadmin-user-login-footer span {
            padding: 0 5px
        }

        .layadmin-user-login-footer a {
            padding: 0 5px;
            color: rgba(0, 0, 0, .5)
        }

        .layadmin-user-login-footer a:hover {
            color: rgba(0, 0, 0, 1)
        }

        .layadmin-user-login-main[bgimg] {
            background-color: #fff;
            box-shadow: 0 0 5px rgba(0, 0, 0, .05)
        }

        .ladmin-user-login-theme ul {
            display: inline-block;
            padding: 5px;
            background-color: #fff
        }

        .ladmin-user-login-theme ul li {
            display: inline-block;
            vertical-align: top;
            width: 64px;
            height: 43px;
            cursor: pointer;
            transition: all .3s;
            -webkit-transition: all .3s;
            background-color: #f2f2f2
        }

        .ladmin-user-login-theme ul li:hover {
            opacity: .9
        }

        @media screen and (max-width: 768px) {
            .layadmin-user-login {
                padding-top: 60px
            }

            .layadmin-user-login-main {
                width: 300px
            }

            .layadmin-user-login-box {
                padding: 10px
            }
        }
    </style>
</head>
<body>
<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">

    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2> [[${configs.title}]]</h2>
        </div>
        <form class="layadmin-user-login-box layadmin-user-login-body layui-form" id="login-form">
            <div class="layui-form-item">
                <label class="layui-form-label">用户名：</label>
                <div class="layui-input-block">
                    <input type="text" name="username" id="LAY-user-login-username" lay-verify="required" placeholder="请输入用户名"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密 码：</label>
                <div class="layui-input-block">
                    <input type="password" name="password" id="LAY-user-login-password" lay-verify="required"
                           placeholder="请输入密码" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">验证码：</label>
                <div class="layui-input-inline">
                    <input type="text" name="imageCode" lay-verify="required" placeholder="请输入验证码"  autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid" style="padding: 0!important;">
                    <img src="/admin/user/letter-number" title="点击刷新验证码" id="image-code">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <div class="layui-input-inline">
                    <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="loginForm">登 录</button>
                </div>
            </div>
        </form>
    </div>

    <div class="layui-trans layadmin-user-login-footer">
        <p>Copyright © 2022 - [[${year}]] [[${configs.copyright}]]</p>
    </div>


</div>
<script src="/statics/layui-v2.8.15/layui.js"></script>
<script src="/statics/js/md5.js"></script>
<script>
    //JavaScript代码区域
    layui.use('form', function () {
        let $ = layui.jquery, form = layui.form;
        $("#image-code").click(function () {
            $(this).attr('src', '/admin/user/letter-number?t=' + Math.random());
        })
        //监听提交
        form.on('submit(loginForm)', function (data) {
            data = data.field;
            data.password = hex_md5(data.password);
            $.post("/admin/user/login", data, function (res) {
                console.log(res);
                if (res.code === undefined || res.code === 0) {
                    let waitTime = 2000, msg = '', sDatetime = new Date().getTime() + 7 * 24 * 3600 * 1000;
                    if (res.data.adminUser.passwordExpireTime < sDatetime) {
                        msg = "：密码即将过期，过期后将无法登录，请及时修改密码";
                        waitTime = 3000
                    }
                    layer.msg('登录成功' + msg);
                    setTimeout(function () {
                        parent.location.href = '/admin/main';
                    }, waitTime);
                } else {
                    $("#image-code").attr('src', '/admin/user/letter-number?t=' + Math.random());
                    layer.msg(res.error);
                }
            });
            return false;
        });
    });
</script>
</body>
</html>